;Metis-rs NSIS Installer
;Based mainly upon Pidgin's NSIS Script.
;Written for Metis-rs by Danny Hand
;Meant to be used with NSIS 2.39 or later

;File last updated: September 3, 2008

;Be sure to check the version before compiling! (line 19)

;--------------------------------
;Use Modern UI 2 (Looks pretty)

  !include MUI2.nsh

;--------------------------------
;General Settings

  ;What version of Metis is this?
  !define PRODUCT_VERSION "3.5.5"

  ;Name of the product
  Name "Metis ${PRODUCT_VERSION}"

  ;Information for the Version tab of the installer's Properties window.
  VIProductVersion "${PRODUCT_VERSION}.0"
  VIAddVersionKey ProductName "Metis ${PRODUCT_VERSION}"
  VIAddVersionKey Comments "Metis ${PRODUCT_VERSION}.  Website:  http://sourceforge.net/projects/metis-rs/"
  VIAddVersionKey CompanyName "Metis Developers"
  VIAddVersionKey LegalCopyright "John Svazic"
  VIAddVersionKey FileDescription "Metis, the first open source RuneScape client!"
  VIAddVersionKey FileVersion "${PRODUCT_VERSION}"
  VIAddVersionKey ProductVersion "${PRODUCT_VERSION}"
  VIAddVersionKey InternalName "Metis ${PRODUCT_VERSION}"
  VIAddVersionKey OriginalFilename "metis-${PRODUCT_VERSION}-win32-installer.exe"

  ;Where to put the installer, and what to name it.
  OutFile "..\..\metis-${PRODUCT_VERSION}-win32-installer.exe"

  ;Default installation folder
  InstallDir "$PROGRAMFILES\Metis"
  
  ;Get installation folder from registry if available
  InstallDirRegKey HKCU "Software\Metis" ""

  ;Request application privileges for Windows Vista
  RequestExecutionLevel user

;--------------------------------
;Interface Settings

  ;Define the images and icons for the installer and uninstaller.
  !define MUI_ICON        "${NSISDIR}/Contrib/Graphics/Icons/modern-install-blue-full.ico"
  !define MUI_UNICON      "${NSISDIR}/Contrib/Graphics/Icons/modern-uninstall-blue-full.ico"
  !define MUI_WELCOMEFINISHPAGE_BITMAP		metis-intro.bmp
  !define MUI_UNWELCOMEFINISHPAGE_BITMAP		metis-intro.bmp

  ;License Page Modifiers
  !define MUI_LICENSEPAGE_BUTTON		"Next >"
  !define MUI_LICENSEPAGE_TEXT_BOTTOM		"$(^Name) is released under the GNU General Public License (GPL). The license is provided here for information purposes only. $_CLICK"

  ;Ask for confirmation before an early exit
  !define MUI_ABORTWARNING

  ;Keep the window open after a successful install
  !define MUI_FINISHPAGE_NOAUTOCLOSE
  !define MUI_UNFINISHPAGE_NOAUTOCLOSE

  ;Final Page Modifiers
  !define MUI_FINISHPAGE_RUN			"$INSTDIR\metis.bat"
  !define MUI_FINISHPAGE_RUN_NOTCHECKED

;--------------------------------
;Pages

  ;Welcome, License, Components, and Installation Directory pages
  !insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_LICENSE "..\..\COPYING"
  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY

  ;Start Menu Folder stuff
  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Metis" 
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Metis"

  ;Installer (Log/Progress Page)
  !insertmacro MUI_PAGE_INSTFILES

  ;Final Page
  !insertmacro MUI_PAGE_FINISH
  
  ;Uninstaller Pages
  !insertmacro MUI_UNPAGE_WELCOME
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  !insertmacro MUI_UNPAGE_FINISH
  
;--------------------------------
;Languages
 
  !insertmacro MUI_LANGUAGE "English"

;--------------------------------
;Installer Section

Section "Metis ${PRODUCT_VERSION} (Required)" SecMetisrs

  ;Disable the checkbox on the component page
  SectionIn RO

  ;Tell where to install to
  SetOutPath "$INSTDIR"
  
  ;Copy every file from \trunk\dist\win32 (windows files built in apache ant).
    File /r ..\..\dist\win32\*.*

  ;Store installation folder in the Registry
  WriteRegStr HKCU "Software\Metis" "" $INSTDIR
  
  ;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"

  ;Add Metis to "Add or Remove Programs" in Control Panel
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "DisplayName" "Metis ${PRODUCT_VERSION}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "DisplayIcon" "${NSISDIR}/Contrib/Graphics/Icons/modern-uninstall-blue.ico"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "NoRepair" 1
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product" "UninstallString" "$INSTDIR\Uninstall.exe"

SectionEnd

;--------------------------------
;Desktop Shortcut Section

Section "Desktop Shortcut" SecDesktopShortcut
  SetOverwrite on
    CreateShortCut "$DESKTOP\Metis.lnk" "$INSTDIR\metis.bat"
  SetOverwrite off
SectionEnd

;--------------------------------
;Start Menu Shortcuts Section

Section "Start Menu Shortcuts" SecStartShortcut
  SetOverwrite on
    CreateDirectory "$SMPROGRAMS\Metis"
    CreateShortCut "$SMPROGRAMS\Metis\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
    CreateShortCut "$SMPROGRAMS\Metis\Metis.lnk" "$INSTDIR\metis.bat"
    CreateShortCut "$SMPROGRAMS\Metis\Metis Folder.lnk" "$INSTDIR"
  SetOverwrite off
SectionEnd

;--------------------------------
;Descriptions (For the component selection page)

  ;Define the descriptions
  LangString DESC_SecMetisrs ${LANG_ENGLISH} "Metis, the first open-source RuneScape client."
  LangString DESC_SecDesktopShortcut ${LANG_ENGLISH} "Places a shortcut to metis.bat on your desktop."
  LangString DESC_SecStartShortcut ${LANG_ENGLISH} "Places shortcuts to metis.bat, the uninstaller, and the installation directory in your start menu."


  ;Assign descriptions to the sections
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${SecMetisrs} $(DESC_SecMetisrs)
    !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} $(DESC_SecDesktopShortcut)
    !insertmacro MUI_DESCRIPTION_TEXT ${SecStartShortcut} $(DESC_SecStartShortcut)
  !insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;Uninstaller Section

Section "Uninstall" SecUninstall

  ;Delete all these files.
  Delete "$INSTDIR\COPYING"
  Delete "$INSTDIR\IeEmbed.exe"
  Delete "$INSTDIR\jdic.dll"
  Delete "$INSTDIR\metis.bat"
  Delete "$INSTDIR\metis.jar"
  Delete "$INSTDIR\MozEmbed.exe"
  Delete "$INSTDIR\README"
  Delete "$INSTDIR\Metis-installer.nsi"
  Delete "$INSTDIR\lib\activation.jar"
  Delete "$INSTDIR\lib\hippolf.jar"
  Delete "$INSTDIR\lib\htmlparser.jar"
  Delete "$INSTDIR\lib\IeEmbed.exe"
  Delete "$INSTDIR\lib\ilf-gpl.jar"
  Delete "$INSTDIR\lib\irclib.jar"
  Delete "$INSTDIR\lib\jdic.dll"
  Delete "$INSTDIR\lib\jdic.jar"
  Delete "$INSTDIR\lib\log4j-1.2.13.jar"
  Delete "$INSTDIR\lib\mail.jar"
  Delete "$INSTDIR\lib\MozEmbed.exe"
  Delete "$INSTDIR\lib\napkinlaf.jar"
  Delete "$INSTDIR\lib\nimrodlf.jar"
  Delete "$INSTDIR\lib\smoothmetal.jar"
  Delete "$INSTDIR\lib\substance.jar"
  Delete "$INSTDIR\nsis\Metis-installer.nsi"
  Delete "$INSTDIR\nsis\metis-intro.bmp"
  Delete "$INSTDIR\nsis\modern-install-blue-full.ico"
  Delete "$INSTDIR\nsis\modern-uninstall-blue-full.ico"
  Delete "$INSTDIR\nsis\thumbs.db"
  Delete "$INSTDIR\nsis\NSI-CHANGES"
  Delete "$INSTDIR\nsis\NSI-README"

  ;Delete the 'lib' and 'nsis' folders.
  RMDir "$INSTDIR\lib"
  RMDir "$INSTDIR\nsis"

  ;Delete the uninstaller.
  Delete "$INSTDIR\Uninstall.exe"

  ;Remove the installation directory.
  RMDir "$INSTDIR"

  ;Remove Start Menu folder and shortcuts, and Desktop shortcuts  
  Delete "$SMPROGRAMS\Metis\Uninstall.lnk"
  Delete "$SMPROGRAMS\Metis\Metis.lnk"
  Delete "$SMPROGRAMS\Metis\Metis Folder.lnk"
  Delete "$DESKTOP\Metis.lnk"
  RMDir "$SMPROGRAMS\Metis"

  ;Remove Metis from the Registry
  DeleteRegKey /ifempty HKCU "Software\Metis"

SectionEnd

;--------------------------------
;end of file
